package com.lixl.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * 模拟线程池实现<br>
 * 用5个线程来执行20个任务
 * @author Administrator
 *
 */
public class MyThreadPoolDemo {

	private static BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(20);
	
	public static void main(String[] args) throws InterruptedException {
		
		for (int i = 0; i < 20; i++) {
			Runnable work = new MyThreadPoolDemo.Worker(""+i);
			workQueue.add(work);
		}
		
		for (int i = 0; i < 5; i++) {
			Thread thread = new Thread(workQueue.take());
			thread.start();
		}
		
		
	}
	
	static class Worker implements Runnable{
		private String id;
		public Worker(String id) {
			this.id = id;
		}

		@Override
		public void run() {
			System.out.println(id+"\t"+Thread.currentThread().getName()+" running");
		}
		
	}
	
	
	
	
	public void execute(Runnable task){
		
	}

}
